<template>
	<view class="mainPage">
		<view class="plate">
			<view class="tip-box" v-if="isBank">
				<view class="tip-word">您暂没有填写过有关汇款账户信息</view>
				<view class="btn-tip" @click="showBank">请增加</view>
			</view>
			<view class="edit-box" v-else>
				<u-cell-group>
					<u-cell-item :arrow="false">
						<view slot="title">银行开户账户名：</view>
						<view slot="right-icon"><u-input v-model="bankInfo.accountName" type="text"
								placeholder="请输入开户行账户名" :border="false" /></view>
					</u-cell-item>
					<u-cell-item :arrow="false">
						<view slot="title">银行账号：</view>
						<view slot="right-icon"><u-input v-model="bankInfo.accountNo" type="text" placeholder="请输入银行账号"
								:border="false" /></view>
					</u-cell-item>
					<u-cell-item :arrow="false">
						<view slot="title">开户行名称：</view>
						<view slot="right-icon"><u-input v-model="bankInfo.bankName" type="text" placeholder="请输入开户行名称"
								:border="false" /></view>
					</u-cell-item>
					<u-cell-item :arrow="false">
						<view slot="title">姓名：</view>
						<view slot="right-icon"><u-input v-model="bankInfo.realName" type="text" placeholder="请输入姓名"
								:border="false" /></view>
					</u-cell-item>
					<u-cell-item :arrow="false">
						<view slot="title">微信号：</view>
						<view slot="right-icon"><u-input v-model="bankInfo.wxNo" type="text" placeholder="请输入微信号"
								:border="false" /></view>
					</u-cell-item>
					<u-cell-item :arrow="false">
						<view slot="title">支付宝账号：</view>
						<view slot="right-icon"><u-input v-model="bankInfo.zfbNo" type="text" placeholder="请输入支付宝账号"
								:border="false" /></view>
					</u-cell-item>

				</u-cell-group>
				<view class="btn" @click="submit">
					提交
				</view>
			</view>
			
		</view>

		<u-toast ref="uToast" />

	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				userInfo: '',
				bankInfo: {
					accountName: "",
					accountNo: "",
					bankName: "",
					realName: "",
					wxNo: "",
					zfbNo: ""
				},
				isBank: false
			};
		},
		onShow() {
			this.userInfo = uni.getStorageSync('userInfo');
			console.log(this.userInfo);
			this.getAccountInfo();

		},

		onLoad() {

		},
		methods: {
			showBank(){
				this.isBank = false;
			},
			getAccountInfo() {
				let that = this;
				this.$u.post("serviceaccounts/getMyInfo/" + this.userInfo.id).then(res => {
					console.log(res)
					if (res) {
						that.isBank = false;
						that.bankInfo = res;
					} else {
						that.isBank = true;
					}
				});
			},
			submit() {
				if (this.bankInfo.accountName == '') {
					this.$refs.uToast.show({
						title: '请输入银行开户账户名',
						type: 'warning'
					})
					return
				}
				if (this.bankInfo.accountNo == '') {
					this.$refs.uToast.show({
						title: '请输入银行账号',
						type: 'warning'
					})
					return
				}
				if (this.bankInfo.bankName == '') {
					this.$refs.uToast.show({
						title: '请输入银行开户行',
						type: 'warning'
					})
					return
				}
				this.$u.post("serviceaccounts/save", this.bankInfo).then(res => {
					console.log(res)
					uni.showToast({
						title: '已提交保存',
						icon: 'none'
					})
					uni.navigateBack();
				});

			}

		}
	}
</script>

<style lang="scss">
	.btn {
		line-height: 70rpx;
		margin-top: 20rpx;
		font-size: 30rpx;
		color: #FFFFFF;
		text-align: center;
		background: linear-gradient(90deg, #FF3868, #FC6161);
		box-shadow: 1px 10px 15px 2px rgba(255, 78, 70, 0.3);
		border-radius: 20rpx;
	}

	page {
		background-color: #f7f7f7;
		padding: 0 30rpx;
		padding-bottom: 30rpx;
		box-sizing: border-box;
	}

	.box {
		background-color: #FFFFFF;
		border-radius: 20rpx;
		padding: 0 30rpx;

		.item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx 0;
			border-bottom: 1rpx solid #E8E7E7;

			>view {
				&:first-child {
					font-size: 28rpx;
				}

				&:last-child {
					display: flex;
					align-items: center;

					text {
						margin-right: 10rpx;
					}
				}
			}

			&:last-child {
				border-bottom: none;
			}
		}
	}

	.tip-box {
		.tip-word {
			font-size: 28rpx;
			color: #6f6f6f;
			padding-top: 20rpx;
			padding-bottom: 20rpx;
		}

		.btn-tip {
			line-height: 100rpx;
			margin-top: 20rpx;
			font-size: 30rpx;
			color: #FFFFFF;
			text-align: center;
			background: linear-gradient(90deg, #FF3868, #FC6161);
			box-shadow: 1px 10px 15px 2px rgba(255, 78, 70, 0.3);
			border-radius: 20rpx;
		}
	}
</style>